﻿using System.Linq;
using System.Windows;
using System.Collections.Generic;
using Game.Map.Internal;
using Game.Common;

namespace Game.Map
{
    public static class MapUtil
    {
        public static IEnumerable<IMapField> GetAdjacentFields(
            IGameMap map, 
            Point point,
            bool includeCenter = false)
        {
            return new AdjacentFields(map, point, includeCenter);
        }

        public static IEnumerable<IMapFieldView> GetAdjacentViewFields(
            IGameMapView view,
            Point point,
            bool includeCenter = false)
        {
            var fields = GetAdjacentFields(view, point);
            return fields.Select(field => view.Collection[field.Point]).ToList();
        }

        public static IMapField GetField(
            IGameMap map,
            Point point, 
            ObjectOrientation orientation)
        {
            return new AdjacentFields(map, point, true)[orientation];
        }

        public static GameFieldCollection GetArea(
            IGameMap map,
            Point point, 
            double size)
        {
            var fields = new GameFieldCollection();

            foreach (var field in map.Fields)
            {
                if (point == field.Point)
                {
                    continue;
                }

                var distance = new DistanceCalc(
                    point, field.Point);

                if (distance.Value <= size)
                {
                    fields.Add(field);
                }
            }

            return fields;
        }

    }
}
